# -*- coding: utf-8 -*-
# @Time    : 2021/11/15 22:10
# @Author  : super
import time



def index():
	status = "200 OK"
	response_header = [("Server", "PWS2.0")]
	with open("../template/index.html", "r",encoding = "utf-8") as f:
		filedata = f.read()
	data = filedata.replace("{%content%}",time.ctime())
	return status, response_header, data

def center():
	status = "200 OK"
	response_header = [("Server", "PWS2.0")]
	with open("../template/center.html", "r",encoding = "utf-8") as f:
		filedata = f.read()
	data = filedata.replace("{%content%}",time.ctime())
	return status, response_header, data

route_list = [
	("/index.html", index),
	("/center.html", center),
]
def not_func():
	status = "400 Not Found"
	response_header = [("Server", "PWS2.0")]
	data = "400 Not Found"
	return status, response_header, data

def handle_request(env):
	request_path = env["request_path"]
	print("接收到的动态请求资源：", request_path)
	for path, func in route_list:
		if path == request_path:
			result = func()
			return result
	else:
		result = not_func()
		return result